class Frontend::ParisesController < Frontend::BaseController
  before_action :set_parise, only: [:destroy]

  def new
    @parise = Parise.new
  end

  def edit
  end

  def create
    @parise = Parise.new(parise_params)
    if @parise.parise_post
      render json: {count: @parise.micopost.parises_num}
    else
     render json: @parise.errors, status: :unprocessable_entity
    end
  end

  def destroy
    micopost = @parise.micopost
    if @parise.delete_parise
      render json: {count: micopost.parises_num}
    else
      render json: @parise.errors, status: :unprocessable_entity
    end
  end

  private

  def set_parise
    para = parise_params
    @parise = Parise.where(user:para['user_id'] ).where(micopost:para['micopost_id']).first
  end

  def parise_params
    params.fetch(:parise, {}).permit!
  end
end
